package com.sakura.controller;

import com.sakura.dbo.ForHelpDTO;
import com.sakura.dto.QueryHelpRequestDTO;
import com.sakura.service.HelpRequestService;
import com.sakura.util.R;
import com.sakura.vo.HelpRequestDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author : Sakura
 * @Date : 2023/11/24 20:59
 * @Description : TODO 求助模块
 */
@Api(value = "/api/help", tags = {"求助模块"})
@RestController
@RequestMapping("/api/help")
//解决跨域问题
@CrossOrigin
public class HelpRequestController {

    @Autowired
    private HelpRequestService helpRequestService;

    /**
     * 接收老人求助信息，给对应的网格员喝管理员发送消息
     *
     * @param forHelpDTO: 存储老人求助的数据传输对象
     * @return R
     * @author Sakura
     * @date 2023/11/24 21:11
     */

    @ApiOperation(value = "接收老人求助信息，给对应的网格员喝管理员发送消息", httpMethod = "POST")
    @PostMapping("/forHelp")
    public R forHelp(@ApiParam(value = "存储老人求助的数据传输对象", type = "ForHelpDTO") @RequestBody ForHelpDTO forHelpDTO) {
        //1、先根据老人id查出老人的基本信息，专门的负责人
        return R.success(helpRequestService.forHelp(forHelpDTO));
    }

    @ApiOperation(value = "根据id查询事件详情")
    @GetMapping("/query/{id}")
    public R getById(@ApiParam(value = "根据id查询事件详情") @PathVariable Long id) {
        //1、先根据id查出事件的的基本信息，
        HelpRequestDTO helpRequestDTO = helpRequestService.getRequestEventById(id);
        return R.success(helpRequestDTO);
    }

    @ApiOperation(value = "根据老人id查询求助记录")
    @GetMapping("/query/list/{elderlyId}")
    public R getListByElderlyId(@ApiParam(value = "根据老人id查询求助记录") @PathVariable Long elderlyId) {
        //1、先根据id查出事件的的基本信息，
        return R.success(helpRequestService.getListByElderlyId(elderlyId));
    }

    @ApiOperation(value = "分页查询所有求助记录")
    @PostMapping("/list")
    public R list(@ApiParam(value = "分页查询所有求助记录") @RequestBody QueryHelpRequestDTO queryHelpRequestDTO) {
        return helpRequestService.getList(queryHelpRequestDTO);
    }

    @ApiOperation(value = "提醒网格员处理信息")
    @PutMapping("/handle/{id}")
    public R list(@ApiParam(value = "分页查询所有求助记录") @PathVariable Long id) {
        return helpRequestService.handleForHelp(id);
    }

}
